package com.techtransteam.techtransteamWeb.controllers;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import org.springframework.transaction.annotation.Transactional;

import com.techtransteam.techtransteamWeb.dal.dao.impl.UserHome;
import com.techtransteam.techtransteamWeb.dal.entities.User;

@ManagedBean(name="userService")
@RequestScoped
public class UserService {

	@ManagedProperty(value="#{UserHome}")
	private UserHome userDAO;
	
	public UserHome getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserHome userDAO) {
		this.userDAO = userDAO;
	}

	@Transactional
	public void addUser(User user){
		userDAO.persist(user);
	}
	
	@Transactional
	public void deleteUser(User user){
		userDAO.remove(user);
	}
	
	@Transactional
	public void updateUser(User user){
		userDAO.merge(user);
	}
	
	public User getUserByID(long id){
		return userDAO.findById(id);
	}
	
	public List<User> getAllUsers(){
		return userDAO.getAllUsers();
	}
	
	
}
